import tkinter as tk
from tkinter import ttk

# 创建主窗口
root = tk.Tk()
root.title("Treeview 示例")

# 创建 Treeview 控件
tree = ttk.Treeview(root)
tree.pack(fill="both", expand=True)

# 定义列
tree["columns"] = ("Column1", "Column2")

# 配置列的标题和宽度
tree.heading("#0", text="Tree", anchor="w")
tree.heading("Column1", text="Column1")
tree.heading("Column2", text="Column2")

tree.column("#0", width=120, anchor="w")
tree.column("Column1", width=100)
tree.column("Column2", width=100)

# 添加节点
parent1 = tree.insert("", "end", text="Parent1", values=("Value1", "Value2"))
child1 = tree.insert(parent1, "end", text="Child1", values=("ChildValue1", "ChildValue2"))
child2 = tree.insert(parent1, "end", text="Child2", values=("ChildValue3", "ChildValue4"))

parent2 = tree.insert("", "end", text="Parent2", values=("Value3", "Value4"))
child3 = tree.insert(parent2, "end", text="Child3", values=("ChildValue5", "ChildValue6"))

# 启动主循环
root.mainloop()